package chat.whiteboard.components.canvas;

import java.awt.Color;
import java.awt.Graphics;
import java.util.Vector;

import javax.swing.JPanel;

import chat.whiteboard.WhiteBoardController;
import chat.whiteboard.draw.elements.Drawing;



public class JCanvas extends JPanel implements ICanvas{
	private static final long serialVersionUID = 5147981563232704067L;
	WhiteBoardController controller = null;
	Vector<Drawing> drawings = null;

	public JCanvas(WhiteBoardController controller) {
		this.controller = controller;
		controller.registerCanvas(this);
		setBackground(Color.white);
		drawings = new Vector<Drawing>();
	}

	public void paint(Graphics g) {
		super.paint(g);
		for (int i = 0; i < drawings.size(); i++) {
//			g.setColor(c)
			Drawing v = (Drawing) drawings.elementAt(i);
			v.draw(g);
		}
	}

	@Override
	public void mouseDown(int x, int y) {
		System.out.println(this.getClass().getName() + " mouseDown");
		controller.draw(x, y);
	}

	@Override
	public void mouseUp(int x, int y) {
		System.out.println(this.getClass().getName() + " mouseUp");
	}

	@Override
	public void addDrawing(Drawing d) {
		drawings.add(d);
	}
}